namespace core {
    export class BaseEuiView extends eui.Component implements IBaseView {
        private _controller: BaseController;
        private _myParent: egret.DisplayObjectContainer;
        private _isInit: boolean;
        private _resources: string[] = null;

        public constructor(controller: BaseController, parent: egret.DisplayObjectContainer) {
            super();
            this._controller = controller;
            this._myParent = parent;
            this._isInit = false;

            this.percentHeight = 100;
            this.percentWidth = 100;
        }

        public isShow(): boolean {
            return this.stage != null && this.visible;
        }

        public addToParent(): void {
            this._myParent.addChild(this);
        }

        public removeFromParent(): void {
            App.DisplayUtils.removeFromParent(this);
        }

        public loadResource(loadComplete: Function, initComplete: Function): void {
            if (this._resources && this._resources.length > 0) {
                App.ResourceUtils.loadResource(this._resources, [], loadComplete, null, this);
                this.once(eui.UIEvent.CREATION_COMPLETE, initComplete, this);
            } else {
                loadComplete();
                initComplete();
            }
        }

        public setVisible(value: boolean): void {
            this.visible = value;
        }

        public get myParent(): egret.DisplayObjectContainer {
            return this._myParent;
        }

        public setResources(resources: string[]): void {
            this._resources = resources;
        }
        public isInit(): boolean {
            return this._isInit;
        }
        public applyFunc(key: any, ...param: any[]): any {
            return this._controller.applyFunc.apply(this._controller, arguments);
        }
        public applyControllerFunc(controllerKey: number, key: any, ...param: any[]): any {
            return this._controller.applyControllerFunc.apply(this._controller, arguments);
        }

        public initUI(): void {
            this._isInit = true;
        }
        public initData(): void {
        }

        public destroy(): void {
            this._controller = null;
            this._myParent = null;
            this._resources = null;
        }

        public open(...param: any[]): void {
        }
        public close(...param: any[]): void {
        }

    }
}